{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <title>绑定邮箱</title>
{#    <link rel="stylesheet" href="{% static 'Form_Style/css/style-nav.css' %}">#}
    <link rel="stylesheet" type="text/css" href="{% static 'index/css/edit.css' %}">
    <link rel="stylesheet" type="text/css" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}">
</head>

<body>
    <div class="row">
        <div class="col-md-12">
            <h2>确认文件：<a class="directory" href="{{ file_database.get_url }}">{{ file_database.name }}</a></h2>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
             <h3>此项操作会指定该文件run完后最终发送的邮箱</h3>
        </div>
    </div>
{#    <label for="name">邮箱选择：</label>#}
{#    <form method="post" href="{% url "file_manage:bind_mail" file_database.pk %}">#}
{#    {% csrf_token %}#}
{#    <div>#}
{#    {% for tmp_email in user_email_database %}#}
{#             <label class="checkbox-inline">#}
{#                    {% if tmp_email in file_email_database %}#}
{#                        <input type="checkbox"  name="{{ tmp_email.email_address }}" checked> {{ tmp_email.email_address }}#}
{#                    {% else %}#}
{#                        <input type="checkbox"  name="{{ tmp_email.email_address }}" > {{ tmp_email.email_address }}#}
{#                    {% endif %}#}
{#            </label>#}
{#        {% endfor %}#}
{#         <br>#}
{#         <button class="btn" onclick="checkboxed_t()" >我确定</button>#}
{#         <a class="directory" href="{{ file_database.get_url }}">返回</a>#}
{#        <label class="checkbox-inline">#}
{#            <input type="checkbox" id="inlineCheckbox1" value="option1"> 选项 1#}
{#        </label>#}
{#        <label class="checkbox-inline">#}
{#            <input type="checkbox" id="inlineCheckbox2" value="option2"> 选项 2#}
{#        </label>#}
{#        <label class="checkbox-inline">#}
{#            <input type="checkbox" id="inlineCheckbox3" value="option3"> 选项 3#}
{#        </label>#}
{#    class表示这一排为一组全选范围#}
    </div>
    </form>
    <form method="post" href="{% url "file_manage:bind_mail" file_database.pk %}">
    {% csrf_token %}
    <table class="table table-bordered">
        <thead>
            <th>组名</th>
            <th>邮箱</th>
            <th>全选</th>
        </thead>
        <tbody>
            {% for tmp_group in Email_group_database %}
                <div class=".col-md-12">
                <tr>
                    <div class=".col-md-12">
                    <th>{{ tmp_group.name }}</th>
                    </div>
                    <th>
                    {% with i=forloop.counter %}
                    {% for tmp_user_email in user_email_database %}
                        {% if tmp_user_email in tmp_group.email_data.all %}
                                {% if tmp_user_email in file_email_database %}
                                     <input type="checkbox" class="{{ i }}" name="{{ tmp_user_email.email_address }}" checked value="{{ tmp_user_email.email_address }}">

                                {% else %}
                                     <input type="checkbox" class="{{ i }}" name="{{ tmp_user_email.email_address }}" value="{{ tmp_user_email.email_address }}">

                                {% endif %}
                                {{ tmp_user_email.email_address }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        {% endif %}
                    {% endfor %}

                    </th>
                    <th>
                        <input  type="checkbox" name="{{ i }}"  onclick="checkallbox(this)">
                    </th>
                </tr>
                </div>
                     {% endwith %}
            {% endfor %}
        </tbody>
    </table>
{#        <br>#}
            <button class="btn" onclick="checkboxed_t()" >我确定</button>
            <a class="directory" href="{{ file_database.get_url }}">返回</a>
    </form>
{#    <div>#}
{##}
{#    </div>#}
{#<script>#}
{#    function checkboxed_t() {#}
{#        $('input:checkbox').attr("checked", true);#}
{#        $('input:checkbox').attr("checked", true);#}
{#    }#}
{#</script>#}
<script>
    //通过全选的name 和单选的class 进行全选复选判定
    function checkallbox(checkbox) {
        var class_id=checkbox.name;
        {#var list=$("."+class_id)#}
        var list_checkbox=document.getElementsByClassName(class_id)
        if(checkbox.checked){
            //选中的时候
            for(var i=0;i<list_checkbox.length;i++) {
                if(!list_checkbox[i].checked){
                    list_checkbox[i].checked=true;
                }
            }
        }else{
            //没选中的时候
            for(var i=0;i<list_checkbox.length;i++) {
                if(list_checkbox[i].checked){
                    list_checkbox[i].checked=false;
                }
            }
        }

    }
</script>
</body>
</html>